#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
// #define ESP32
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
bool wifiConnect()
{
    WiFiManager wm;
    bool res;
    uint8_t macAddr[6];
    WiFi.macAddress(macAddr);
    char SSID[10];
    int i = 0;
    sprintf(SSID, "AP-%X%X", macAddr[4], macAddr[5]);

    wm.setTimeout(180);
    wm.setConnectTimeout(10);
    res = wm.autoConnect(SSID);
    WiFi.hostname("test"); // 连接后再设置host
    if (!res)
    {
        Serial.println("Failed to connect");
        return 0;
    }
    else
    {
        Serial.println("connected...yeey :)");
        return 1;
    }
}
void setup()
{
    Serial.begin(115200);
    wifiConnect();
}

void loop()
{
    // put your main code here, to run repeatedly:
}
